package net.xxcxcxcx.xc_enhancedmob.event;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.util.ActionResult;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;

/**
 * 被攻击的事件
 */
public interface onDamagedCallback {
    Event<onDamagedCallback> EVENT = EventFactory.createArrayBacked(onDamagedCallback.class,
            (listeners) -> (attacker, target, source, amount, ismob, remote) -> {
                for (onDamagedCallback listener : listeners) {
                    ActionResult result = listener.onDamaged(attacker, target, source, amount, ismob, remote);

                    if (result != ActionResult.PASS) {
                        return result;
                    }
                }

                return ActionResult.PASS;
            }
    );

    ActionResult onDamaged(LivingEntity attacker, LivingEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote);
}
